# project = 'Code', file_name = '线程池', author = 'AI悦创'
# time = '2020/3/3 0:05', product_name = PyCharm
# code is far away from bugs with the god animal protecting
#    I love animals. They taste delicious.

import time
import threadpool

# 执行比较耗时的函数，需要开多线程
def get_html(url):
	time.sleep(3)
	print(url)
# 按原本的单线程运行时间为：300s
# 而多线程池的化：30s
# 使用多线程执行 telent 函数
urls = [i for i in range(100)]
pool = threadpool.ThreadPool(10) # 建立线程池

# 提交任务给线程池
requests = threadpool.makeRequests(get_html, urls)

# 开始执行任务
for req in requests:
	pool.putRequest(req)
pool.wait()